package com.zb.util;

import java.util.*;

/**
 * @Author lyx
 * @create 2021/9/3 9:08
 * @description:
 */
public class SortUtil {

    public static List<Map.Entry<String, Long>> mapSort(Map map){

        //将map.entrySet()转换成list
        List<Map.Entry<String, Long>> list = new ArrayList<Map.Entry<String, Long>>(map.entrySet());
        Collections.sort(list, new Comparator<Map.Entry<String, Long>>() {
            //降序排序,升序则交换o1,o2位置
            @Override
            public int compare(Map.Entry<String, Long> o1, Map.Entry<String, Long> o2) {

                return o2.getValue().compareTo(o1.getValue());
            }
        });


        return list;
    }

    public static void main(String[] args) {
        Map<String, Long> map = new HashMap<String, Long>(16);
        map.put("c", 33333L);
        map.put("a", 11111L);
        map.put("d", 44444L);
        map.put("e", 55555L);
        map.put("b", 22222L);

        System.out.println(mapSort(map));
    }
}
